package com.zhonggong.jbdc;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class JDBCTest {
	
	String URL = "jdbc:mysql://202.196.37.91:3306/course";
	String USER = "zutnlp";
	String PASSWORD = "zutnlp";
	Connection conn = null;
	Statement st = null;
	ResultSet rs = null;
	
	public void query() throws SQLException
	{
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = (Connection) DriverManager.getConnection(URL, USER, PASSWORD);
			st = (Statement) conn.createStatement();
			rs = st.executeQuery("select id , fullname from t_student");
			while(rs.next())
			{
				System.out.println(rs.getString(1)+" "+rs.getString(2));
			}
		}catch(ClassNotFoundException e)
		{
			e.printStackTrace();
		}catch(SQLException e)
		{
			e.printStackTrace();
		}finally
		{
				rs.close();
				st.close();
				conn.close();
		}
	}
	
	public static void main(String[] args) throws SQLException {
		// TODO Auto-generated method stub
		JDBCTest jTest = new JDBCTest();
		jTest.query();
	}
}
